package com.Hsu.trans.controller;

import com.Hsu.trans.service.LogService;
import com.Hsu.trans.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Hsu琛君珩
 * @ClassName:ProController
 * @date 2024-01-22
 * @apiNote
 * @Version: v1.0
 */

@Slf4j
@RestController
@RequestMapping("/proga")
public class ProController {
    @Autowired
    private UserService userService;
    @Autowired
    private LogService logService;

    /**
     * 正常操作，没有抛出异常
     */
    @Transactional
    @RequestMapping("/p1")
    public String registry(String userName, String password) {
        Integer result = userService.insertUser(userName, password);
        log.info("用户插入成功，result:" + result);

        Integer result2 = logService.insertLog(userName, "用户自行注册");
        log.info("日志表插入成功，result2:" + result2);
        return "注册成功";
    }
}